package com.luo.ai.assistant.chat.impl;

import com.luo.ai.assistant.util.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.document.Document;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.filter.Filter;

import java.util.List;

/**
 * 向量存储代理实现（目前仅打印相关日志，并无其他作用）
 *
 * @author luohq
 * @date 2025-02-05 14:03
 */
public class MyVectorStore implements VectorStore {

    private static final Logger log = LoggerFactory.getLogger(MyVectorStore.class);

    /**
     * 原向量存储实现
     */
    private VectorStore vectorStore;

    public MyVectorStore(VectorStore vectorStore) {
        this.vectorStore = vectorStore;
    }

    @Override
    public void add(List<Document> documents) {
        log.debug("[VectorStore] add documents - doc count: {}, doc list: {}",documents.size(), JsonUtils.toJson(documents));
        this.vectorStore.add(documents);
    }

    @Override
    public void delete(List<String> idList) {
        log.debug("[VectorStore] delete documents - id count: {}, id list: {}", idList.size(), JsonUtils.toJson(idList));
        this.vectorStore.delete(idList);
    }

    @Override
    public List<Document> similaritySearch(SearchRequest request) {
            log.debug("[VectorStore] similaritySearch request: {}", JsonUtils.toJson(request));
            List<Document> documents = this.vectorStore.similaritySearch(request);
            log.debug("[VectorStore] similaritySearch result - doc count: {}, doc list: {}", documents.size(), JsonUtils.toJson(documents));
            return documents;
    }

    @Override
    public void delete(Filter.Expression filterExpression) {
        log.debug("[VectorStore] delete documents by filter - filter: {}", JsonUtils.toJson(filterExpression));
        this.vectorStore.delete(filterExpression);
    }
}
